package com.ljy.my_study.java.gc;

/**
 * @author lijunying
 * @date 2021/1/5 14:35
 */
public class OnStackTest {

    public static class User{
        public int age;
        public String name="";
        public byte[] content;
    }

    /**
     * 非逃逸对象，将对象打散在栈上，调用完方法后就自行回收
     * 当对象的属性过大后栈上分配失败
     */
    public static void alloc(){
        User user=new User();
        user.name="James";
        user.age=20;
//        user.content=new byte[1*1000];
    }

    /**
     * -server -Xmx1000m -Xms1000m -XX:+DoEscapeAnalysis -XX:+PrintGCDetails -XX:+EliminateAllocations -XX:+TraceClassUnloading -XX:+TraceClassLoading
     * @param args
     */
    public static void main(String[] args) {
        long start=System.currentTimeMillis();
        for(long i=0;i<1_0000_0000L;i++){
            alloc();
        }
        long end=System.currentTimeMillis();
        System.out.println(end-start);
    }
}
